package 数组中出现次数超过一半的数字;

class Solution {
    public int moreThanHalfNum_Solution(int[] nums) {
        int val = 0, cnt = 0;
        for (int i = 0; i < nums.length; i++) {
            if (cnt == 0) {
                val = nums[i];
                cnt++;
            } else {
                if (val == nums[i]) {
                    cnt++;
                } else {
                    cnt--;
                }
            }
        }
        return val;
    }
}